package com.example.My.controller;

import com.example.My.auToken.EmailCodeAuthenticationToken;
import com.example.My.common.ResponseResult;
import com.example.My.pojo.LoginUser;
import com.example.My.pojo.User;
import com.example.My.service.LoginService;
import com.example.My.service.context.LoginContext;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Author: 谢宇
 * CreatTime 2023/11/5 11:16
 * Version 1.0.0
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    LoginService loginService;


    @PostMapping ("/login")
    public ResponseResult login(@RequestBody User user, @Param(value = "type")String type) throws NoSuchMethodException {
        LoginContext loginContext=new LoginContext(loginService);
        return  loginContext.doThings(type, user);
    }

    //codeName可以是手机号或者是邮箱
    @PostMapping("sendCode")
    public ResponseResult<String> sendCode(String CodeName){
        Authentication code=new EmailCodeAuthenticationToken(CodeName);
        return loginService.sendCode(code);
    }


}
